<template>
  <div class="products-detail container">
    <!-- 面包屑 -->
    <div class="bread-crumb container">
      <el-breadcrumb separator-class="el-icon-arrow-right">
        <el-breadcrumb-item>{{ $t("yunLianUsedMachine") }}</el-breadcrumb-item>
        <el-breadcrumb-item to="/products">{{ $t("products") }}</el-breadcrumb-item>
        <el-breadcrumb-item>{{ productsDetail.bigTypeName }}</el-breadcrumb-item>
        <el-breadcrumb-item>{{ productsDetail.subTypeName }}</el-breadcrumb-item>
      </el-breadcrumb>
    </div>
    <!-- 设备title、规格参数、社媒分享 -->
    <div class="header-view">
      <el-image
        class="info-img"
        fit="cover"
        :src="productsDetail.coverImage"
        :preview-src-list="[productsDetail.coverImage]"
        lazy
        :alt="productsDetail.subTypeName"
      ></el-image>
      <div class="info-right">
        <div class="info-right-top">
          <div class="info-title">{{ productsDetail.skuName }}</div>
          <p class="sku-desc">{{ productsDetail.categoryName }}</p>
          <div class="sku-data">
            <div class="sku-data-one" v-for="item in kuSpecsList" :key="item.id">
              <img :src="item.specsIcon" />
              <div class="font-9">{{ item.specsName }}</div>
              <div class="font-7">{{ item.specsValue }}</div>
            </div>
          </div>
        </div>
        <div class="info-share" v-if="locale == 'en-US'">
          <img src="https://yunlian-oss-product.oss-cn-hangzhou.aliyuncs.com/website/facebook.png" alt="facebook" @click="mediaShare('facebook')" />
          <img src="https://yunlian-oss-product.oss-cn-hangzhou.aliyuncs.com/website/twitter.png" alt="twitter" @click="mediaShare('twitter')" />
          <img src="https://yunlian-oss-product.oss-cn-hangzhou.aliyuncs.com/website/linkedin.png" alt="linkedin" @click="mediaShare('linkedin')" />
        </div>
      </div>
    </div>
    <div class="view-title" v-if="productsDetail && productsDetail.categoryFeatureList.length">{{ $t("features") }}</div>
    <div class="product-features" v-if="productsDetail && productsDetail.categoryFeatureList.length">
      <div class="features-item" v-for="item in productsDetail.categoryFeatureList" :key="item.id">
        <p>{{ item.featureTitle }}</p>
        <span>{{ item.featureContent }}</span>
      </div>
    </div>
    <div class="view-title">{{ $t("specsCompare") }}</div>
    <div class="compare-params">
      <div class="params-item" v-for="item in productsDetail.kuSpecsList" :key="item.id">
        <div class="item-canshu" :title="item.specsName">{{ item.specsName }}</div>
        <div class="item-canshu" :title="item.specsValue">{{ item.specsValue }}</div>
      </div>
    </div>
    <!-- 侧边栏服务 -->
    <Dangling v-if="locale == 'zh-CN'" />
    <!-- WhatsApp -->
    <!-- <WhatsApp v-if="locale == 'en-US'" /> -->
    <!-- 在线客服 -->
    <Connect />
  </div>
</template>

<script>
import { mapState } from "vuex"
import BigNumber from "bignumber.js"
export default {
  name: "ProductsDetail",
  layout: "Layout",
  data() {
    return {
      hostUrl: "",
      routeUrl: ""
    }
  },
  head() {
    return {
      title: `【${this.productsDetail.skuName}】-${this.productsDetail.skuName}${this.$i18n.t("detailHeadTitle")}`,
      meta: [
        {
          hid: "keywords",
          name: "keywords",
          content: this.$i18n.t("haeaKeyContent")
        },
        {
          hid: "description",
          name: "description",
          content: this.$i18n.t("haeaDecContent")
        },
        {
          property: "og:title",
          content: `${this.productsDetail.skuName}`
        },
        {
          property: "og:description",
          content: this.$i18n.t("haeaDecContent")
        },
        {
          property: "og:url",
          content: `${this.hostUrl}${this.routeUrl}`
        },
        {
          property: "og:image",
          content: `${this.productsDetail.coverImage}`
        }
      ]
    }
  },
  async asyncData({ app, params }) {
    let paramsRes = params.detailParams
    console.log("paramsRes", paramsRes)
    let skuId = paramsRes //设备ID
    let productsDetail = {}, //设备详情
      kuSpecsList = [] //规格参数
    try {
      let { data } = await app.$api.skuDetails({ skuId })
      productsDetail = data
      kuSpecsList = productsDetail.kuSpecsList.filter((v) => v.isMainSpecs == 1)
    } catch (error) {
      console.log("error", error)
    }
    return {
      productsDetail,
      kuSpecsList
    }
  },
  props: {},
  computed: { ...mapState(["locale"]) },
  watch: {},
  async mounted() {
    this.$cookies.set("msgInfo", true) //缓存检索存储值
    this.currentUrl()
    this.getPoint()
  },
  methods: {
    currentUrl() {
      setTimeout(() => {
        if (process.client) {
          this.hostUrl = `${window.location.host}`
          this.routeUrl = `${this.$route.fullPath}`
        }
      }, 1000)
    },
    mediaShare(type) {
      let linkUrl = ""
      let url = encodeURIComponent(`${window.location.host}${this.$route.fullPath}`)
      if (type == "facebook") {
        linkUrl = `http://www.facebook.com/sharer.php?u=${url}&t=${this.productsDetail.skuName}`
        _hmt.push(["_trackEvent", "button", "click", `分享设备到facebook，设备ID-${this.productsDetail.skuId}`])
      } else if (type == "twitter") {
        linkUrl = `https://twitter.com/intent/tweet?url=${url}&title=${this.productsDetail.skuName}`
        _hmt.push(["_trackEvent", "button", "click", `分享设备到twitter，设备ID-${this.productsDetail.skuId}`])
      } else if (type == "linkedin") {
        linkUrl = `https://www.linkedin.com/shareArticle?mini=true&url=${url}&title=${this.productsDetail.skuName}`
        _hmt.push(["_trackEvent", "button", "click", `分享设备到linkedin，设备ID-${this.productsDetail.skuId}`])
      }
      window.open(linkUrl, "_blank")
    },
    async getPoint() {
      let params = await this.$optionPoint.sendUrl(window, navigator, document)
      this.$api.burySave({ ...params }).then((res) => {})
    }
  }
}
</script>

<style lang="scss" scoped>
.products-detail {
  display: flex;
  flex-direction: column;
  .bread-crumb {
    margin-top: 30px;
  }
  .header-view {
    display: flex;
    justify-content: space-between;
    margin-top: 30px;
    .info-img {
      width: 610px;
      height: 400px;
      border: 1px solid #e0e0e0;
    }
    .info-right {
      width: 550px;
      height: 400px;
      display: flex;
      flex-direction: column;
      .info-right-top {
        .info-title {
          font-size: 22px;
          font-weight: 500;
          color: #333;
          line-height: 24px;
        }
        .sku-desc {
          font-size: 18px;
          font-weight: 500;
          color: #707070;
          margin-top: 10px;
        }
        .sku-data {
          width: 550px;
          background: #f6f7f9;
          padding: 40px 20px;
          box-sizing: border-box;
          display: flex;
          justify-content: space-evenly;
          margin-top: 20px;
          .sku-data-one {
            width: 33.33%;
            display: flex;
            flex-direction: column;
            align-items: center;
            img {
              width: 60px;
              height: 60px;
            }
            .font-9 {
              font-size: 16px;
              font-weight: 500;
              color: #333;
              line-height: 20px;
              text-align: center;
              margin-top: 10px;
            }
            .font-7 {
              font-size: 16px;
              font-weight: 500;
              color: #e60012;
              margin-top: 10px;
            }
          }
        }
      }
      .info-share {
        display: flex;
        align-items: center;
        justify-content: right;
        margin-top: 20px;
        padding-right: 10px;
        box-sizing: border-box;
        img {
          width: 40px;
          height: 40px;
          cursor: pointer;
        }
      }
    }
  }
  .view-title {
    font-family: PingFangSC, PingFang SC;
    font-weight: 600;
    font-size: 22px;
    color: #333;
    border-left: 3px solid #fb463f;
    padding-left: 5px;
    margin-top: 50px;
  }
  .product-features {
    margin-top: 10px;
    .features-item {
      box-shadow: 0px 2px 10px 0px rgba(0, 0, 0, 0.1);
      padding: 15px 20px;
      box-sizing: border-box;
      margin-top: 20px;
      p {
        font-weight: 700;
        font-size: 18px;
        color: #000;
        margin-bottom: 20px;
      }
      span {
        font-weight: 500;
        font-size: 16px;
        color: #504f4f;
        line-height: 20px;
      }
    }
  }
  .compare-params {
    margin-top: 30px;
    margin-bottom: 50px;
    box-shadow: 0px 2px 10px 0px rgba(0, 0, 0, 0.1);
    padding: 15px 20px;
    box-sizing: border-box;
    .params-item {
      display: flex;
      align-items: center;
      .item-canshu {
        width: 300px;
        height: 50px;
        line-height: 50px;
        font-size: 16px;
        border: #333;
        border-bottom: 1px solid #d9d9d9;
        &:nth-child(2) {
          margin-left: 20px;
        }
      }
    }
  }
}
</style>
